package com.platform.hjt.sys.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hjt.tools.code.MD5;
import com.platform.hjt.base.controller.BaseController;
import com.platform.hjt.base.controller.ReturnBody;
import com.platform.hjt.sys.service.SysUserInfoService;

@Controller
@RequestMapping(value="/login")
public class LoginController extends BaseController{
	
	@Resource
	private SysUserInfoService sysUserInfoService;
	
	@RequestMapping(value="/login.html")
	public String loginPage(){
		return "page/admin/login";
	}
	
	@RequestMapping(value="/login.do")
	@ResponseBody
	public ReturnBody loginDo(@RequestParam(value="account", required=true) String userAccount,
			@RequestParam(value="pwd", required=true)String userPwd){
		return sysUserInfoService.handleCheckUserInfo(userAccount, userPwd);
	}
	
	public String indexPage(){
		return "page/admin/index";
	}
	
	@RequestMapping(value="/change_pwd.html")
	public String changePwd(){
		return "page/admin/change_pwd";
	}
	
	@RequestMapping(value="/change_pwd.do")
	@ResponseBody
	public ReturnBody changePwd(HttpServletRequest request){
		request.setAttribute("filter_EQB_isDel", "false");
		request.setAttribute("filter_EQS_userAccount", request.getParameter("username"));
		request.setAttribute("filter_EQS_userPwd", MD5.enPasswd(request.getParameter("username"), request.getParameter("password")));
		return sysUserInfoService.handleChangePwd();
		//return new ReturnBody(true, "密码修改", "login/login.html");
	}
	
	@RequestMapping(value="/logout.do")
	@ResponseBody
	public ReturnBody logoutDo(HttpServletRequest request){
		//removeSessionUser();
		return new ReturnBody(true, "登出成功", "admin/login.html");
	}
	
	
}
